import io from 'socket.io-client'
const socket = io('ws://127.0.0.1:7001', {
  reconnection: true, // 是否重连
  reconnectionAttempts: 30, // 重新连接的次数
  reconnectionDelay: 1000, // 每过多长时间重连一次
  timeout: 5000, // 超时时间
  query: {
    token: window.sessionStorage.getItem('token'),
  },
})

socket.on('connect', () => {
  console.log('连接成功') // x8WIv7-mJelg7on_ALbx
  console.log('socket', socket)
  socket.io.on('res', (data) => {
    console.log('data:', data)
  })
  // console.log(socket.io.emit('server', { msg: '前端' }))
})

// 接收在线用户信息
socket.on('online', (msg) => {
  console.log('#online,', msg)
})

socket.on('disconnect', (res) => {
  console.log('连接关闭') // undefined
})

socket.on('client_success', (response) => {
  console.log('client_success:', response)
})

export default socket
